package com.team2.insulatingtools.modular.tools.controller;


import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.team2.insulatingtools.modular.tools.pojo.request.QuotaRequest;
import com.team2.insulatingtools.modular.tools.service.QuotaService;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;


/**
 * 定额 控制器
 *
 * @author team2
 * @date 2023/04/03 09:48
 */
@RestController
@ApiResource(name = "定额")
public class QuotaController {

    @Resource
    private QuotaService quotaService;


    @GetResource(name = "获取当前登录用户可操作的班组", path = "/api/quota/optionalOrg")
    public ResponseData optionalOrg() {
        return quotaService.selOptionalOrg();
    }


    @GetResource(name = "获取班组可选工具", path = "/api/quota/optionalTools")
    public ResponseData optionalTools(String orgId) {
        return quotaService.selOptionalTool(orgId);
    }


    @PostResource(name = "添加定额", path = "/api/quota/save")
    public ResponseData save(@RequestBody QuotaRequest request) {
        return quotaService.add(request);
    }


    /**
     * 获取指定班组的定额列表
     * @author team2
     * @date 2023/04/03 09:48
     */
    @GetResource(name = "获取指定班组的定额列表", path = "/api/quota/teamQuotoList")
    public ResponseData teamQuotoList(String orgId) {
        return quotaService.selTeamQuota(orgId);
    }


    /**
     * 获取当前用户可操作的所有定额列表
     * @author team2
     * @date 2023/04/03 09:48
     */
    @GetResource(name = "获取当前用户可操作的所有定额列表", path = "/api/quota/allQuotoList")
    public ResponseData allQuotoList() {
        return quotaService.selAllQuota();
    }

    /**
     * 删除定额信息
     * @author team2
     * @date 2023/04/03 09:48
     */
    @PostResource(name = "删除定额信息", path = "/api/quota/del")
    public ResponseData del(@RequestBody Map<String,Integer> map) {
        return quotaService.del(map.get("id"));
    }


    @GetResource(name = "查询定额更改的历史记录", path = "/api/quota/selQuotaLog")
    public ResponseData selQuotaLog(String quotaId) {
        return quotaService.selQuotaLog(quotaId);
    }

    @PostResource(name="定额更改-增加",path="/changeQuota/add")
    public ResponseData addQuota(@RequestBody @Validated(QuotaRequest.edit.class) QuotaRequest quotaRequest){
        quotaService.addQuota(quotaRequest);
        return new SuccessResponseData();
    }

    @PostResource(name="定额更改-删除",path="/changeQuota/delete")
    public ResponseData quotaDelete(@RequestBody QuotaRequest quotaRequest){
        quotaService.batchDeleteTools(quotaRequest);
        return new SuccessResponseData();
    }

    @GetResource(name="定额更改-可删除列表",path="/changeQuota/deleteList")
    public ResponseData quotaDeleteList(QuotaRequest quotaRequest){
        return new SuccessResponseData(quotaService.selectToolQuotaList(
                quotaRequest.getOrgId(),quotaRequest.getId()));
    }


    @GetResource(name = "查询车间或班组的定额列表", path = "/api/quota/workshopOrTeamQuotoList")
    public ResponseData workshopOrTeamQuotoList(String orgId) {
//        if (StringUtils.hasLength(orgId)){
//            return quotaService.selWorkshopOrTeamQuota(orgId);
//        } else {
//            return quotaService.selAllQuota();
//        }
        return quotaService.selWorkshopOrTeamQuota(orgId);
    }


}
